//==================================================================
//  Copyright (C) 2006  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
///
///
///
///
///
//==================================================================

#include "camfly.h"

//==================================================================
using namespace PMath;

//==================================================================
void CamFly::Update(void)
{
	_cam_mat.Identity();
	_cam_mat *= Matrix44::RotY( _ang._y );
	_cam_mat *= Matrix44::RotX( _ang._x );

	*_cam_mat.GetRow3(3) = _offs;
}

//==================================================================
void CamFly::Setup( float px, float py, float pz,
					float ax, float ay, float az )
{
	_offs.Set( px, py, pz );
	_ang.Set( ax, ay, az );	

	Update();
}

//==================================================================
void CamFly::Update( float dpx, float dpy, float dpz,
						   float dax, float day, float daz )
{
	Vector3	dir;

	_ang._x += dax;
	_ang._y += day;
	_ang._z += daz;

	dir = Vector3( dpx, dpy, dpz );

	_step_smooth = dir * 0.25f + _step_smooth * 0.75f;
	_ang_smooth = Vector3( dax, day, daz ) * 0.25f + _ang_smooth * 0.75f;

	_cam_mat.Identity();
	_cam_mat *= Matrix44::RotY( _ang._y );
	_cam_mat *= Matrix44::RotX( _ang._x );

	_offs += _cam_mat * dir;
	
//	_cam_mat *= Matrix44::RotZ( -_step_smooth._x / 1 );
//	_cam_mat *= Matrix44::RotZ( _ang_smooth._y * 8  );

//	_cam_mat *= Matrix44::RotX( _step_smooth._z / 2.5f );

	*_cam_mat.GetRow3(3) = _offs;
}

//==================================================================
const Matrix44	&CamFly::GetMatrix(void) const
{
	return _cam_mat;
}
